import 'package:flutter/material.dart';
// import 'package:widgets/input/Counter.dart';
import 'package:widgets/input/CounterFieldExample.dart';

class FormFieldExample extends StatefulWidget {
  @override
  _FormFieldExampleState createState() => _FormFieldExampleState();
}

class _FormFieldExampleState extends State<FormFieldExample> {
  final _formKey = GlobalKey<FormState>();
  String name;
  int age;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("FormFieldExample"),
      ),
      body: Center(
        child: Form(
          key: this._formKey,
          child: Column(
            mainAxisSize: MainAxisSize.min,
            children: [
              Text('Please fill in your name and age'),
              TextFormField(
                autovalidate: false,
                onSaved: (value) => this.name = value,
                validator: (value) {
                  return value.length < 3
                      ? 'a minimum of 3 characters is required'
                      : null;
                },
              ),
              //Counter(),
              CounterFieldExample(
                autovalidate: false,
                onSaved: (value) => this.age = value,
                validator: (int value) {
                  print(value);
                  return value < 0 ? 'Negative values not supported' : null;
                },
              ),
              RaisedButton(
                child: Text('Submit'),
                onPressed: () {
                  if (this._formKey.currentState.validate()) {
                    setState(() {
                      this._formKey.currentState.save();
                    });
                  }
                },
              ),
              SizedBox(height: 50.0),
              Text('${this.name} is ${this.age} years old')
            ],
          ),
        ),
      ),
    );
  }
}
